/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

/**
 *
 * @author Carlos, Edward, Diego, Honorio
 */
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Conexao {

    public static Connection getConnection() throws AirLineDAOException {
        try {
            Class.forName("org.postgresql.Driver");             // Driver do banco de dados
            String bd = "jdbc:postgresql://localhost/airline"; // URL para o banco de dados
            String usr = "postgres";                            // Usuario para o banco de dados
            String pswrd = "neto";                          // Senha para o banco de dados
            return DriverManager.getConnection(bd, usr, pswrd); //Parametros para a conexao
        } catch (Exception e) {                                 //Em caso de erro/excecao
            throw new AirLineDAOException(e.getMessage());
        }
    }

    public static void closeConnection(Connection conn, Statement stat, ResultSet rs)
            throws AirLineDAOException {
        close(conn, stat, rs);
    }

    public static void closeConnection(Connection conn, Statement stat)
            throws AirLineDAOException {
        close(conn, stat, null);
    }

    public static void closeConnection(Connection conn) throws AirLineDAOException{
        close(conn, null, null);
    }

    private static void close(Connection conn, Statement stat, ResultSet rs)
            throws AirLineDAOException {
        try {
            if (conn != null) conn.close();
            if (stat != null) stat.close();
            if (rs != null) rs.close();
        } catch (Exception e) {
            throw new AirLineDAOException(e.getMessage());
        }
    }
}

